package core

import (
	"github.com/hajimehoshi/ebiten/v2"
	"github.com/solarlune/resolv"
)

type Sprite struct {
	Base
	Position  *resolv.Vector
	Scale     *resolv.Vector
	Rotate    float64
	Image     *ebiten.Image
	Collision *resolv.ConvexPolygon
	IsDestory bool
	Tag       struct {
		Name    string
		Visible bool
		Delete  bool
	}
}

func (s *Sprite) GetCollision() *resolv.ConvexPolygon {
	return s.Collision
}
func (s *Sprite) GetCenter() resolv.Vector {
	w := float64(s.Image.Bounds().Dx()) * s.Scale.X
	h := float64(s.Image.Bounds().Dy()) * s.Scale.Y

	return resolv.NewVector(s.Position.X+w/2, s.Position.Y+h/2)
}
func (s *Sprite) SetPosition(p resolv.Vector) {
	s.Position.X = p.X - s.GetWH().X/2
	s.Position.Y = p.Y - s.GetWH().Y/2
}
func (s *Sprite) Move(x, y float64) {
	s.Position.X += x
	s.Position.Y += y
	if s.Collision != nil {
		s.Collision.SetPosition(s.GetCenter().X, s.GetCenter().Y)
	}
}
func (s *Sprite) MoveVec(vec resolv.Vector) {
	s.Move(vec.X, vec.Y)
}

func (s *Sprite) GetWH() resolv.Vector {
	w := float64(s.Image.Bounds().Dx()) * s.Scale.X
	h := float64(s.Image.Bounds().Dy()) * s.Scale.Y
	return resolv.NewVector(w, h)
}

func (s *Sprite) Destory() {
	s.IsDestory = true
}
func (s *Sprite) GetDestory() bool {
	return s.IsDestory
}

//	func (s *Sprite) GetProjectileMovement() *ProjectileMovement {
//		return nil
//	}
func (s *Sprite) GetTimer() []*Timer {
	return s.Timer
}

type ISprite interface {
	Update(dt float64) error
	Draw(screen *ebiten.Image)
	GetCollision() *resolv.ConvexPolygon
	Destory()
	GetDestory() bool
	MoveVec(vec resolv.Vector)
	GetTimer() []*Timer
	//UpdateTimer(dt float64)
	//StartTimer(duration float64, task TimerTask, isLooping bool)
	//GetProjectileMovement() *ProjectileMovement
}
